package win;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;

public class 四按钮java窗口 extends JFrame implements ActionListener {
    private JButton inputStudentInfoButton;
    private JButton inputContestInfoButton;
    private JButton downloadScoreTableButton;
    private JButton showBigDataButton;

    public 四按钮java窗口() {
        setTitle("周赛成绩系统");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(400, 300);
        setLocationRelativeTo(null);

        // 设置全局背景颜色为淡蓝色
        getContentPane().setBackground(new Color(173, 216, 230));

        JPanel mainPanel = new JPanel(new BorderLayout());
        mainPanel.setBorder(new EmptyBorder(20, 20, 20, 20));

        JPanel buttonPanel = new JPanel(new GridLayout(4, 1, 10, 10));
        buttonPanel.setBackground(new Color(224, 255, 255));

        inputStudentInfoButton = new JButton("录入学生信息");
        inputStudentInfoButton.addActionListener(this);
        buttonPanel.add(inputStudentInfoButton);

        inputContestInfoButton = new JButton("录入周赛信息");
        inputContestInfoButton.addActionListener(this);
        buttonPanel.add(inputContestInfoButton);

        downloadScoreTableButton = new JButton("下载成绩表格");
        downloadScoreTableButton.addActionListener(this);
        buttonPanel.add(downloadScoreTableButton);

        showBigDataButton = new JButton("显示成绩大数据的 HTML");
        showBigDataButton.addActionListener(this);
        buttonPanel.add(showBigDataButton);

        mainPanel.add(buttonPanel, BorderLayout.CENTER);

        add(mainPanel);
    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == inputStudentInfoButton) {
            // 调用录入学生信息的已有代码
            JOptionPane.showMessageDialog(this, "录入学生信息功能已触发。");
        } else if (e.getSource() == inputContestInfoButton) {
            // 调用录入周赛信息的已有代码
            JOptionPane.showMessageDialog(this, "录入周赛信息功能已触发。");
        } else if (e.getSource() == downloadScoreTableButton) {
            // 根据你提供的路径下载成绩表格
            try {
                // 假设你的表格路径为 /path/to/scoreTable.csv
                File scoreTableFile = new File("src/main/webapp/html/src/Excel/研发中心牛客周赛 Round 70 成绩表.xlsx");
                if (scoreTableFile.exists()) {
                    Desktop.getDesktop().open(scoreTableFile);
                } else {
                    JOptionPane.showMessageDialog(this, "成绩表格文件不存在。");
                }
            } catch (IOException ex) {
                ex.printStackTrace();
                JOptionPane.showMessageDialog(this, "下载失败！");
            }
        } else if (e.getSource() == showBigDataButton) {
            try {
                // 假设你的 HTML 文件路径为 /path/to/bigData.html
                Desktop.getDesktop().browse(new File("src/main/webapp/index.html").toURI());
            } catch (IOException ex) {
                ex.printStackTrace();
                JOptionPane.showMessageDialog(this, "无法显示成绩大数据 HTML。");
            }
        }
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new 四按钮java窗口().setVisible(true);
            }
        });
    }
}